﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFIDA.U9.AP.Enums;
using UFIDA.U9.CBO.FI.Enums;
using UFIDA.U9.CBO.SCM.Item;
using UFIDA.U9.SM.SO;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;
using UFSoft.UBF.Util.DataAccess;

namespace UFIDA.U9.CusDev.QJKJPlugInBE
{
    class ProcessForAPtoARAPCA : IEventSubscriber
    {
        public void Notify(params object[] args)
        {

            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent)) return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;

            if (key == null || key.GetEntity() == null) return;
            //应付->应收冲应付
            UFIDA.U9.AP.ARAPCounterApply.ARAPCAHead ap = key.GetEntity() as UFIDA.U9.AP.ARAPCounterApply.ARAPCAHead;
            if (ap == null) return;


            #region 应收->应收冲应付 下面的应收单行必须只能有一行
            int a = 0;
            foreach (var line in ap.ARAPCALineForUIs)
            {
                if (line.ARBillTag > 0)
                {
                    ++a;
                    if (a > 1)
                    {
                        throw new Exception("对冲应收单只能有一行!");

                    }
                }
                
            }
            #endregion
        }

    }
}
